import time
from retrying import retry
import requests

num = 1
get_url = "https://www.360buy.com"
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0',
}


@retry(stop_max_attempt_number=3)
def get_info(url):
    global num
    print(f"第{num}次请求")
    num += 1
    response = requests.get(url, headers=headers, timeout=3)
    for i in response.history:
        # 判断状态码是否为200, 抛出异常
        # if i.status_code != 200:
        #     raise Exception("请求失败")
        # 使用断言的方式抛出异常
        assert i.status_code == 200
    print(response)


try:
    get_info(get_url)
except Exception as e:
    print("程序异常：", e)
